#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
deque<int> q;  // 保存的是下标，方便比较
int n, m;
ll s[N], a[N], ans = -0x3f3f3f3f3f3f3f3f;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
  }
  q.push_back(0);  // 为啥
  for (int i = 1; i <= n; ++i) {
    while (q.size() && q.front() < i - m) q.pop_front();
    ans = max(ans, s[i] - s[q.front()]);
    while (q.size() && s[q.back()] >= s[i]) q.pop_back();
    q.push_back(i);
  }
  cout << ans << endl;
  return 0;
}
